//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __DEBUGSTUB_H__
#define __DEBUGSTUB_H__

//
// CDebuggerStub
//
class CDebuggerStub : public CDeviceDriver
{
public:
    CARAPI Read(
        /* [in] */ Int64 u64Offset,
        /* [in] */ Int32 bytesToRead,
        /* [out] */ MemoryBuf * pBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Write(
        /* [in] */ Int64 u64Offset,
        /* [in] */ const MemoryBuf & buffer,
        /* [out] */ Int32 * pBytesWritten,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Control(
        /* [in] */ Handle32 nControlCode,
        /* [in] */ const MemoryBuf & inBuffer,
        /* [out] */ MemoryBuf * pOutBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    CDebuggerStub();

    virtual void Dispose();

private:
    CARAPI WriteProcessMemory(
        /* [in] */ HANDLE hProcess,
        /* [in] */ PVoid lpBaseAddress,
        /* [in] */ PCVOID lpBuffer,
        /* [in] */ size_t nSize,
        /* [out] */ size_t * lpNumberOfBytesWritten);

    CARAPI GetThreadStackBase(
        /* [in] */ DWORD dwProcessId,
        /* [in] */ DWORD dwThreadId,
        /* [in] */ PVoid * ppStackBase);

    CARAPI GetLastErrorCode();

private:
    DWORD   m_dwTargetProcessId;
    HANDLE  m_hTargetProcess;
};

//
// CDebuggerStubManager
//
class CDebuggerStubManager : public CDeviceDriver
{
public:
    CARAPI Read(
        /* [in] */ Int64 u64Offset,
        /* [in] */ Int32 bytesToRead,
        /* [out] */ MemoryBuf * pBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Write(
        /* [in] */ Int64 u64Offset,
        /* [in] */ const MemoryBuf & buffer,
        /* [out] */ Int32 * pBytesWritten,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Control(
        /* [in] */ Handle32 nControlCode,
        /* [in] */ const MemoryBuf & inBuffer,
        /* [out] */ MemoryBuf * pOutBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    virtual void Dispose();
};

#endif // __DEBUGSTUB_H__
